# coding:utf-8
from io import BytesIO
with BytesIO() as f:
    f.write('中文'.encode('utf-8'))
    print(f.getvalue())
    
    
    
print("-------------读取-----------------")
with BytesIO(b'\xe4\xb8\xad\xe6\x96\x87') as f:
    print(f.read())
    
    
#StringIO和BytesIO是在内存中操作str和bytes的方法，使得和读写文件具有一致的接口。